package icu.feigroup.domain.activity.service.discount.impl;

import icu.feigroup.domain.activity.model.valobj.GroupActivityDiscountVO;
import icu.feigroup.domain.activity.service.discount.AbstractDiscountCalculateService;
import icu.feigroup.types.common.Constants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * projectName:icu.feigroup.domain.activity.service.discount.impl
 *
 * @author 飞
 * @since 2025/2/20 10:26
 * description:
 */
@Service("MJ")
@Slf4j
public class MJDiscountCalculate extends AbstractDiscountCalculateService {
    @Override
    protected BigDecimal doCalculate(BigDecimal originPrice, GroupActivityDiscountVO.GroupDiscount groupDiscount) {
        String marketExpr = groupDiscount.getMarketExpr();
        String[] split = marketExpr.split(Constants.SPLIT);
        BigDecimal x = new BigDecimal(split[0]);
        BigDecimal y = new BigDecimal(split[1]);

        //例如，满足100才满减
        if (originPrice.compareTo(x)<0){
            return originPrice;
        }
        //BigDecimal的计算不能使用符号
        BigDecimal deductionPrice = originPrice.subtract(y);
        //不能0元购，有最低价格
        return compareZero(deductionPrice);
    }
}
